<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/6
 * Time: 20:55
 */


require_once "../../php/config/database.php";
require_once "userDb.php";

$UserDb=new UserDb();
$userA=$_POST['user'];

$pass=$_POST['pass'];
$pass=md5($pass);
session_start();
$user = $_SESSION['user'];

$dataA=$UserDb->adminClass($user);
$class=$dataA[0]['className'];
$addtime=time();
$datea=$UserDb->selectUser($userA);
if($datea==null) {
    $data = $UserDb->add_user($userA, $class,$pass,$user,$addtime);
    try {
        $result = $data;
        if ($result) {
            $dat = array(
                'message' =>"注册成功",
            );
            echo json_encode($dat);
        } else {
            $dat = array(
                'message' =>"注册失败",

            );
            echo json_encode($dat);

        }
    }
    catch (Exception $e) {

        // 回滚事务
        // $pdo->rollback();
        echo $e->getMessage();}

}
else
{

    $dat = array(

        'message' =>"该账号以及存在，请登陆",
        'data'=>$datea,

    );
    echo json_encode($dat);


}

